<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <title>邮件管理</title>
    <link rel="stylesheet" type="text/css" href="./easyui/themes/bootstrap/easyui.css">
    <link rel="stylesheet" type="text/css" href="./easyui/themes/icon.css">
    <link rel="stylesheet" type="text/css" href="./easyui/themes/color.css">
    <script type="text/javascript" src="./easyui/jquery.min.js"></script>
    <script type="text/javascript" src="./easyui/jquery.easyui.min.js"></script>
    <script type="text/javascript" src="./js/common.js"></script>
</head>
<body>
    <div class="easyui-panel" style="padding:15px 5px;width:100%;">
        当前用户：<span id="login_user"></span> | 切换用户：<input id="cc" name="cuser" value=""> |
        <a href="javascript:void(0)" onclick="sendMaid()" class="easyui-linkbutton" data-options="iconCls:'icon-email'">发送日报</a>
    </div>
    <div class="easyui-panel" style="padding:15px 5px;width:100%;">
      <a href="report.html" class="easyui-linkbutton" data-options="toggle:true,group:'g2',plain:true ">日报管理</a>
        <a href="plan.html" class="easyui-linkbutton" data-options="toggle:true,group:'g2',plain:true">计划管理</a>
      <a href="mail.html" class="easyui-linkbutton" data-options="toggle:true,group:'g2',plain:true ,selected:true">邮件管理</a>
        <a href="log.html" class="easyui-linkbutton" data-options="toggle:true,group:'g2',plain:true ">发送记录</a>
  </div>


    <table id="dg" data-options="rownumbers:true,singleSelect:true" style="width:100%;">

    </table>

  <div id="w" class="easyui-window" title="新增" data-options="iconCls:'icon-save',closed:true" style="width:400px;height:240px;padding:10px;">
      <form id="ff" method="post">
          <table style="width:100%;">

              <tr>
                  <td>邮箱地址:</td>
                  <td><input name="mail" class="easyui-textbox"></input>
                    <input name="id" hidden>
                  </td>
              </tr>
              <tr>
                  <td>姓名:</td>
                  <td><input name="name" class="easyui-textbox"></input></td>
              </tr>
              <tr>
                  <td>类型:</td>
                  <td>
                      <select class="easyui-combobox" name="type" style="width:179px;">
                          <option value="0" selected>发送</option>
                          <option value="1" >抄送</option>

                      </select></td>
              </tr>
              <tr>

                  <td colspan="2" style="text-align:center;padding-top:20px;">

                      <a href="javascript:void(0)" class="easyui-linkbutton" onclick="submitForm()" style="width:80px">提交</a>
                      &nbsp;&nbsp;&nbsp;
                      <a href="javascript:void(0)" class="easyui-linkbutton" onclick="cannel()" style="width:80px">取消</a>
                  </td>
              </tr>
          </table>
      </form>
  </div>

 
    <script type="text/javascript">
        var toolbar = [{
            text:'新增',
            iconCls:'icon-add',
            handler:function(){
                $('#ff').form('clear');
                $('#w').window('open')
            }
        },{
            text:'删除',
            iconCls:'icon-remove',
            handler:function(){
                var select = $('#dg').datagrid('getSelected');
                if(select == null){
                    $.messager.alert('提示','请选中要删除的数据');
                    return;
                }
                $.messager.confirm('确认','是否删除?',function(r){
                    if (r){
                        del(select)
                    }
                });
            }
        }];

        $('#dg').datagrid({
            columns:[[
                {field:'mail',title:'地址',width:400},
                {field:'name',title:'姓名',width:200},
                {field:'type',title:'类型',width:200,formatter: function(value,row,index){

				if(value==0){
				    return '发送';
				}else{
                    return '抄送';
				}
			}}
            ]],
            toolbar:toolbar,
            onDblClickRow:function(index,row){
                $('#w').window('open');
                $('#w').form('load',row)
            }
        });
        function loadData(){
            $.cget('mail/getAll.do',{},function(data){
                $('#dg').datagrid('loadData',{"rows":data.data});
            });
        }

        loadData();
        function submitForm(){
            var d={};
            var t = $('#ff').serializeArray();
            $.each(t, function() {
              d[this.name] = this.value;
            });
            if(d.id!=null&&d.id.length>0){
                modify(d);
            }else{
                add(d);
            }

        }

        function del(data){
             $.cpost('mail/delete.do',data,function(data){
                $.messager.alert('提示','删除成功');
                loadData();
            });
        }

        function add(data){
            $.cpost('mail/add.do',data,function(data){
                $.messager.alert('提示','添加成功');
                $('#w').window('close');
                $('#ff').form('clear');
                loadData();
            });
        }
        function modify(data){
            $.cpost('mail/modify.do',data,function(data){
                $.messager.alert('提示','修改成功');
                $('#w').window('close');
                $('#ff').form('clear');
                loadData();
            });
        }

        function cannel(){

            $('#w').window('close');
        }

    </script>
    <script type="text/javascript" src="./js/common_head_hand.js"></script>
</body>
</html>
